package com.oneraku.service.utils;

import com.oneraku.service.domain.AgentStepInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: hui.ren@huberbuy.com
 * @Date: 2020/5/18 13:25
 */
public class StepEnum {

    public static String getName(Integer step){
        if(BuyStepEnum.check(step)){
            return BuyStepEnum.getMsg(step);
        } else if(SkillStepEnum.check(step)){
            return SkillStepEnum.getMsg(step);
        } else if(TransferStepEnum.check(step)){
            return TransferStepEnum.getMsg(step);
        } else {
            return "";
        }
    }
    public static String getMessage(Integer step){
        if(BuyStepEnum.check(step)){
            return "代购-"+BuyStepEnum.getMsg(step);
        } else if(SkillStepEnum.check(step)){
            return "代购-"+SkillStepEnum.getMsg(step);
        } else if(TransferStepEnum.check(step)){
            return "代购-"+TransferStepEnum.getMsg(step);
        } else {
            return "";
        }
    }
    public enum BuyStepEnum {
//        询价=》已报价=》确认付款=》待购买=》购买确认=》等待入库通知=》入库确认
        step1(0,"询价"),
        step2(1,"已报价"),
        step3(2,"确认付款"),
        step4(3,"待购买"),
        step5(4,"购买确认"),
        step6(5,"等待入库通知"),
        step7(6,"入库确认");
        private Integer step;
        private String name;
        BuyStepEnum(Integer step, String name) {
            this.step = step;
            this.name = name;
        }
        public static List<AgentStepInfo> getStepList(String agentId){
            return Arrays.asList(BuyStepEnum.values()).stream().map(item ->{
                AgentStepInfo step =  new AgentStepInfo();
                step.setInfo("");
                step.setAgentId(agentId);
                step.setAgentStep(item.step);
                return step;
            }).collect(Collectors.toList());
        }

        public static boolean check(int step){
            return Arrays.stream(com.oneraku.service.utils.StepEnum.BuyStepEnum.values()).filter(item->item.step.intValue() == step).count() > 0;
        }

        public static String getMsg(Integer step){
            BuyStepEnum[] vals = BuyStepEnum.values();
            for(int i=0;i<vals.length;i++){
                if(vals[i].step.intValue() == step.intValue()){
                    return vals[i].name;
                }
            }
            return "";
        }
    }
    public enum SkillStepEnum {
//        申请=》接受委托=》付款=》拍卖中=》
//        拍卖成功=》等待入库=》入库确认=》历史记录
//        拍卖失败=》退款
        step1(10,"申请"),
        step2(11,"接受委托"),
        step3(12,"已付款"),
        step4(13,"拍卖中"),
        step5(14,"拍卖成功"),
        step6(15,"等待入库"),
        step7(16,"入库确认"),
        step8(17,"拍卖失败"),
        step9(18,"已退款");
        private Integer step;
        private String name;
        SkillStepEnum(Integer step, String name) {
            this.step = step;
            this.name = name;
        }
        public static boolean check(int step){
            return Arrays.stream(com.oneraku.service.utils.StepEnum.SkillStepEnum.values()).filter(item->item.step.intValue() == step).count() > 0;
        }
        public static List<AgentStepInfo> getStepList(String agentId){
            return Arrays.asList(SkillStepEnum.values()).stream().map(item ->{
                AgentStepInfo step =  new AgentStepInfo();
                step.setInfo("");
                step.setAgentId(agentId);
                step.setAgentStep(item.step);
                return step;
            }).collect(Collectors.toList());
        }
        public static String getMsg(Integer step){
            SkillStepEnum[] vals = SkillStepEnum.values();
            for(int i=0;i<vals.length;i++){
                if(vals[i].step.intValue() == step.intValue()){
                    return vals[i].name;
                }
            }
            return "";
        }
    }
    public enum TransferStepEnum {
//        收到货物=》初步商检入库（等待客户集货指令）=》收到客户集货指令=》集货完成=》发货=》后续跟单=》归档
        step1(20,"收到货物"),
        step2(21,"初步商检入库（等待客户集货指令）"),
        step3(22,"收到客户集货指令"),
        step4(23,"集货完成"),
        step5(24,"发货"),
        step6(25,"后续跟单"),
        step7(26,"归档");
        private Integer step;
        private String name;
        TransferStepEnum(Integer step, String name) {
            this.step = step;
            this.name = name;
        }
        public static List<AgentStepInfo> getStepList(String agentId){
            return Arrays.asList(TransferStepEnum.values()).stream().map(item ->{
                AgentStepInfo step =  new AgentStepInfo();
                step.setInfo("");
                step.setAgentId(agentId);
                step.setAgentStep(item.step);
                return step;
            }).collect(Collectors.toList());
        }
        public static boolean check(int step){
            return Arrays.stream(com.oneraku.service.utils.StepEnum.TransferStepEnum.values()).filter(item->item.step.intValue() == step).count() > 0;
        }
        public static String getMsg(Integer step){
            TransferStepEnum[] vals = TransferStepEnum.values();
            for(int i=0;i<vals.length;i++){
                if(vals[i].step.intValue() == step.intValue()){
                    return vals[i].name;
                }
            }
            return "";
        }
    }
}
